var Ccanvas;
var Cgeometry;
var CzBox;
var Czoom = "none";	
function drawing(Geometries, fill, fillcolor, canvas){
	if (canvas.getContext) {
		var lines = canvas.getContext("2d");
		lines.beginPath();
		
		for (var i = 0; i < Geometries.length; i++) {
			if (Geometries[i].type != "point") {
			
				for (var j = 0; j < Geometries[i].geometry.length; j++) {
				
					if (j == 0) {
						lines.moveTo(Geometries[i].geometry[j].x, Geometries[i].geometry[j].y);
					}
					else {
						lines.lineTo(Geometries[i].geometry[j].x, Geometries[i].geometry[j].y);
					}
				}
			}
			if (Geometries[i].type == "point") {
				lines.moveTo(Geometries[i].geometry.x, Geometries[i].geometry.y);
				lines.arc(Geometries[i].geometry.x, Geometries[i].geometry.y, 4, Math.PI * 2, 0, true);
			}
		}
		if (fill == true) {
			lines.fillStyle = '#' + fillcolor;
			lines.fill();
		}
		lines.strokeStyle = '#' + fillcolor;
		lines.stroke();
		lines.closePath();
	}
}
function getpixelsize(CzBox, canvas)
{
	var lw = CzBox.Xmax - CzBox.Xmin;
	
	var pixel = Math.round((lw/width)*100)/100;
	
	return pixel;
}
function createZoomBox(A, B, bxy)
{
		var ZBox = {
		Xmin: A.x + bxy,
		Xmax: B.x - bxy,
		Ymin: B.y + bxy,
		Ymax: A.y - bxy
	};
	return ZBox;
}
function canvasEvents(type)
{
	Czoom = type;
}
function zoom()
{
	if (Czoom == "zoomin") {
		clearcanvas();
		var Zbox = createZoomBox(CreatePoint(CzBox.Xmin, CzBox.Ymax), CreatePoint(CzBox.Xmax, CzBox.Ymin), 100);
		CzBox = Zbox;
		var gitem = transform(Cgeometry, Zbox, canvas.width, canvas.height);
		drawing(gitem, false, "00f", canvas);
	}
	if (Czoom == "zoomout") {
		clearcanvas();
		var Zbox = createZoomBox(CreatePoint(CzBox.Xmin, CzBox.Ymax), CreatePoint(CzBox.Xmax, CzBox.Ymin), -100);
		CzBox = Zbox;
		var gitem = transform(Cgeometry, Zbox, canvas.width, canvas.height);
		drawing(gitem, false, "00f", canvas);
	}
}
function clearcanvas(){
	Ccanvas.width = Ccanvas.width;
}
